<%@page import="multiface.valentinorusso.jpa.Opzioni"%>
<%@page import="multiface.valentinorusso.jpa.Lavoro"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page import="multiface.valentinorusso.jpa.util.PersistenceManager"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="multiface.valentinorusso.jpa.Categoria"%>
<%@page import="multiface.web.util.categories.AlberoCategorie"%>
<%
    String tipo = request.getParameter("tipo");
    String sez = request.getParameter("sez");
    String pag = request.getParameter("page");

    if (tipo == null) {
        tipo = "GENERALE";
    }

    EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
    EntityManager em = emf.createEntityManager();

    Opzioni opz = em.find(Opzioni.class, 1);

%>


<style>
    .plus{
        display: none;
        height: 16px;
        width: 360px;
        float: left;
        margin-left: 6px;
    }
    .plus img{
        cursor: pointer;
    }
    .plus_all{
        height: 20px;
        width: 300px;
        float: right;
        margin-left: 6px;

        text-align: right;
    }
    .plus_all a{
        text-decoration: none;
        color: white;
        font-size: 10px;
        margin-right: 6px;
    }
    .plus a{
        text-decoration: none;
        font-size: 10px;
        margin-right: 6px;
    }
    textarea{
        font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
    }
    i{
        font-size: 10px;
    }
</style>
<script>
    $(document).ready(function(){
        $("#formBox").validate({
            rules: {
                max_record_page_admin: {
                    required: true,
                    number: true
                },
                max_record_page: {
                    required: true,
                    number: true
                }
            }
        });
        //nicEditors.allTextAreas({buttonList : ['bold','italic','underline','ul','ol']}); 
    });

    function save(){
        if($("#formBox").valid()){
            if(parseInt($('#categoria').val()) != null){
                $.post("ActionServlet", 
                { 
                    oid:1,
                    email_contatto:$("#email_contatto").val(),
                    smtp_host:$("#smtp_host").val(),
                    smtp_user:$("#smtp_user").val(),
                    smtp_password:$("#smtp_password").val(),
                    max_record_page:$("#max_record_page").val(),
                    max_record_page_admin:$("#max_record_page_admin").val(),
                    max_pag_paginator:$("#max_pag_paginator").val(),
                    
                    tipo:'<%=tipo%>',
                    adm:'<%=session.getId()%>',
                    action:'mod_opzioni'
                },
                function(data){ 
                    location.href= "index.jsp?adm=<%=session.getId()%>&page=<%=pag%>&sez=<%=sez%>&message="+data;
                });
            }
        }
    }
</script>


<div id="content" style="margin-top: 10px;width: 620px;float: left;text-align: left;">
    <div class="title">
        OPZIONI
    </div>
    <form class="cmxform" id="formBox" method="post" action="">
        <table class="table-form" >
            
            <tr>
                <td style="width: 180px;">Smtp Host*</td>
                <td style="width: 520px;"><input type="text" name="smtp_host" id="smtp_host" size="60" class="required" minlength="4" value="<%=opz.getSmtpHost()%>"/></td>
            </tr>
            <tr>
                <td style="width: 180px;">Smtp User*</td>
                <td style="width: 520px;"><input type="text" name="smtp_user" id="smtp_user" size="60" class="required" minlength="4" value="<%=opz.getSmtpUser()%>"/></td>
            </tr>
            <tr>
                <td style="width: 180px;">Smtp Password*</td>
                <td style="width: 520px;"><input type="password" name="smtp_password" id="smtp_password" size="60" class="required" minlength="4" value="<%=opz.getSmtpPassword()%>"/></td>
            </tr>

            <tr>
                <td style="width: 180px;">Righe-Pagine*</td>
                <td style="width: 520px;"><input type="text" name="max_record_page" id="max_record_page" size="60" value="<%=opz.getMaxRecordPag()%>"/></td>
            </tr>

            <tr>
                <td style="width: 180px;">Righe-Pagine Amm.*</td>
                <td style="width: 520px;"><input type="text" id="max_record_page_admin" name="max_record_page_admin" size="60" value="<%=opz.getMaxRecordPagAdmin()%>"/></td>
            </tr>

            <tr>
                <td style="width: 180px;">Numero di Pagine Visibili*</td>
                <td style="width: 520px;"><input type="text" id="max_pag_paginator" name="max_pag_paginator" size="60" value="<%=opz.getMaxPagPaginator()%>"/></td>
            </tr>
            <tr>
                <td style="width: 120px;">Email di Contatto*<i>(Separate da punto e virgola per mail multiple)</i></td>
                <td style="width: 580px;">
                    <textarea type="text" name="email_contatto" id="email_contatto" size="60" class="required" minlength="4"><%=opz.getEmailContatto()%></textarea>
                </td>
            </tr>

        </table>
        <div class="save-form"><a href="javascript:save()">SALVA</a></div> 
    </form>
</div>
<%
    em.close();
%>